<%--
    Document   : temp
    Created on : Oct 4, 2012, 4:10:02 PM
    Author     : MinhThang
--%>

<%@page import="java.sql.Connection"%>
<%@page import="org.apt.Bean.NewEntities"%>
<%@page import="com.myapp.DAO.NewsDao"%>
<%@page import="org.apt.connectDB.Tools"%>
<%@page import="java.util.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <link href="style/css/transdmin.css" rel="stylesheet" type="text/css" media="screen" />
        <link href="../style/style.css" rel="stylesheet" type="text/css" media="screen" />
        <!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="style/css/ie6.css" /><![endif]-->
        <!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="style/css/ie7.css" /><![endif]-->

        <!-- JavaScripts-->
        <script type="text/javascript" src="style/js/jquery.js"></script>
        <script type="text/javascript" src="style/js/jNice.js"></script>
    </head>
    <body>
        <%
                    if (session.getAttribute("AdminUser") == null || session.getAttribute("AdminUser").toString() == "") {
                        response.sendRedirect("/Admin/adminlogin.jsp");
                    }
        %>
        <div id="wrapper">
            <h1><a href="#"><span>Admin Paper Presentation</span></a></h1>
            <div><%@include file="Template/header.jsp" %></div>
            <div id="containerHolder">
                <div id="sidebar">
                    <ul class="sideNav">
                        <li class="limenu"><a href="addnews.jsp">Addnews</a></li>
                    </ul>
                    <!-- // .sideNav -->
                </div>
                <h2><a href="#">News >></a> <a href="#">List News >></a> <a href="#" class="active">Edit News</a></h2>
                <div id="main">
                    <table>
                        <tr>
                            <td><h3>Title</h3></td>
                            <td></td>
                        </tr>
                        <%
                                    int pageno = 1;
                                    int totalpage = Tools.getTotalPage("News") / 10;
                                    if (Tools.getTotalPage("News") % 10 > 0) {
                                        totalpage = totalpage + 1;
                                    }

                                    try {
                                        int pagenumber = Integer.parseInt(request.getParameter("pageno"));
                                        if (pagenumber > 1) {
                                            pageno = pagenumber;
                                        }
                                        if (pagenumber < 1) {
                                            pageno = 1;
                                        }
                                        if (pagenumber > totalpage) {
                                            pageno = totalpage;
                                        }
                                        List<NewEntities> listNew = NewsDao.getNews(pageno);
                                        if (listNew == null) {
                                            return;
                                        } else {
                                            for (NewEntities news : listNew) {
                        %>
                        <tr>
                            <td><b> <%= news.getTile()%></b></td>
                            <td>
                                <a href="newsdetail.jsp?ID=<%=news.getNewID()%>">Detail</a> |
                                <a href="newsupdate.jsp?ID=<%=news.getNewID()%>">Edit</a> |
                                <a href="../../deleteNews?ID=<%=news.getNewID()%>" onclick="return confirm('Are you sure?')">Delete</a>
                            </td>
                        </tr>
                        <%}
                                        }
                                    } catch (Exception ex) {
                                        ex.printStackTrace();
                                    }
                        %>
                        <tr>
                            <td colspan="2">
                                <div align="center">
                                    <a class="button" href="/Admin/adminnews.jsp?pageno=1"> FIRST </a>
                                    <a class="button" href="/Admin/adminnews.jsp?pageno=<%=pageno - 1%>"> BACK </a>
                                    <input id="pagestatus" type="text" disabled value="<%=pageno%>/<%=totalpage%>" style="width: 70px; text-align: center" />
                                    <a class="button" href="/Admin/adminnews.jsp?pageno=<%=pageno + 1%>"> NEXT </a>
                                    <a class="button" href="/Admin/adminnews.jsp?pageno=<%=totalpage%>"> LAST </a>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="clear"></div>
            </div>
        </div>
    </body>
</html>
